<template>
<div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="200px">
      <!--添加门店-->
      <div class="common-form">{{$t('setting.edit_eorder_template')}}</div>
      <el-form-item :label="$t('setting.eorder_template_name')" prop="templateName" :rules="[{  required: true,  message: ' '}]">
        <el-input v-model="form.templateName" class="max-w460"></el-input>
      </el-form-item>
      <el-form-item :label="$t('setting.eorder_template_code')" prop="templateNum" :rules="[{  required: true,  message: ' '}]">
        <el-input v-model="form.templateNum" class="max-w460"></el-input>
        <div class="tips">{{$t('setting.eorder_tip')}}</div>
      </el-form-item>
      <el-form-item :label="$t('setting.sort_order')">
        <el-input v-model="form.sort" type="number" class="max-w460"></el-input>
        <div class="tips">{{$t('setting.sort_order_tip')}}</div>
      </el-form-item>
      <!--提交-->
      <div class="common-button-wrapper"><el-button type="primary" @click="onSubmit" :loading="loading">{{$t('setting.submit_button')}}</el-button></div>
    </el-form>
  </div>
</template>

<script>
import SettingApi from '@/api/setting.js';
export default {
  data() {
    return {
      /*切换菜单*/
      // activeIndex: '1',
      /*form表单数据*/
      form: {
        templateId: '',
        templateName: '',
        templateNum: '',
        wxCode: '',
        sort: ''
      },
      loading: false
    };
  },
  created() {
    this.getData();
  },
  methods: {
    /*获取数据*/
    getData() {
      let self = this;
      // 取到路由带过来的参数
      const params = this.$route.query.templateId;
      SettingApi.templateDetail({
        templateId: params
      }, true).then(res => {
        let detail = res.data;
        // 将数据放在当前组件的数据内
        self.form.templateId = detail.templateId;
        self.form.templateName = detail.templateName;
        self.form.templateNum = detail.templateNum;
        self.form.sort = detail.sort;
        self.form.wxCode = detail.wxCode;
      }).catch(error => {});
    },
    /*提交表单*/
    onSubmit() {
      let self = this;
      self.loading = true;
      let params = this.form;
      SettingApi.edittemplate(params, true).then(data => {
        self.loading = false;
        ElMessage({
          message: $t("setting.edit_success_message"),
          type: 'success'
        });
        self.$router.push('/setting/template/index');
      }).catch(error => {
        self.loading = false;
      });
    }
  }
};
</script>

<style>
.tips {
  color: #ccc;
}
</style>

